package com.javaGame.util;

import java.awt.*;

/**
 * 图片切换算法类
 */
public class ImageChange {
    /**图片下标*/
    private int index;
    /**计数器*/
    private int count;
    /**切换频率*/
    private int num;

    public ImageChange(int num){
        this.num = num;
    }

    /**
     * 切换图片
     * @param imgArray 要切换的图片数组
     * @return 当前应该绘制的图片
     */
    public Image change(Image[] imgArray){
        this.count++;
        if(this.count >= num){
            this.count = 0;
            this.index ++;
        }

        if(this.index >= imgArray.length){
            this.index = 0;
        }
        return imgArray[index];
    }
}
